Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Ragazzi ciao a tutti, sto cercando di prendere dei dati in formato Json da un sito web, e importarli in un array in vb.net, per fare questo uso la libreria in oggetto e questo codice:
Codice sorgente - presumibilmente VB.NET
Imports System.Net
Imports System.IO
Imports System.Linq
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e As EventArgs)HandlesMyBase.Load
Dim jResults As JObject = JObject.Parse(JObject.Parse(rawresp))
Dim results As List(Of JToken)= jResults.Children().ToList()
ForEach item As JProperty In results
item.CreateReader()
MsgBox(item.Value("img"))' because my tag in json is img
Next
Catch ex As Exception
Console.WriteLine(ex.ToString)
MsgBox(ex.ToString)
Finally
IfNot response IsNothingThen response.Close()
EndTry
EndSub
EndClass
ma , quando lo eseguo ricevo questo errore:
Codice sorgente - presumibilmente Python
Eccezione first-chance di tipo 'Newtonsoft.Json.JsonReaderException'in Newtonsoft.Json.dll
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item isnot an object: StartArray. Path'', line 1, position 1.
in Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
in Newtonsoft.Json.Linq.JObject.Parse(String json)
in NHD.Form1.Form1_Load(Object sender, EventArgs e)in C:\Users\Davide\Documents\Visual Studio 2012\Projects\NHD\NHD\Form1.vb:riga 22
Dim results As List(Of JToken)= jResults.Children().ToList()
ForEach item As JProperty In results
item.CreateReader()
MsgBox(item.Value("Nome"))' because my tag in json is nome
Next
Catch ex As Exception
Console.WriteLine(ex.ToString)
MsgBox(ex.ToString)
Finally
IfNot response IsNothingThen response.Close()
EndTry
l'errore è :
Codice sorgente - presumibilmente Python
Eccezione first-chance di tipo 'Newtonsoft.Json.JsonReaderException'in Newtonsoft.Json.dll
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item isnot an object: StartArray. Path'', line 1, position 1.
in Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
in Newtonsoft.Json.Linq.JObject.Parse(String json)
in NHD.Form1.Form1_Load(Object sender, EventArgs e)in C:\Users\Davide\Documents\Visual Studio 2012\Projects\NHD\NHD\Form1.vb:riga 23